define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Industryrankingsone,$stateParams, GoPage, GoShare, GoDialog, GoWapAuth) {
		
		$scope.store_id = $stateParams.store_id;//店铺id
		
		//页面激活
		$scope.$on('$ionicView.afterEnter', function() {
			$scope.init_data();//初始化
		}, false);
		
		//跳转到行业排名
		$scope.onshow_industryrankings = function(type) {
			GoPage.go_states("industryrankings");
		};
		
		//详情
		$scope.init_data = function(){
			Industryrankingsone.getvotestoreinfo($scope.store_id,function(data){
				$scope.detail = data.result;
				$scope.go_share_wx();
			})
		}
		
		
		//投票--一天内不能重复投票==通过cookie在app不行
        $scope.vote = function() {
        	$scope.voteTime = localStorage.getItem('votedTime');//获取投票时间
			$scope.nowTime = new Date().getTime();//现在的时间戳:js的时间戳是毫秒
			if($scope.nowTime-$scope.voteTime>=86400000){//是否相差一天
				Industryrankingsone.get_vote($scope.store_id, function(data) {
	                if(data.success){
	                    GoDialog.toast("投票成功！");
						localStorage.setItem('votedTime', $scope.nowTime);//在本地内存增加投票时的时间						
	                }else{
	                   GoDialog.toast(data.msg);
	                }
	            });
			}else{
				GoDialog.toast("一天内不能重复投票！");
			}
        }
		
		//分享qq和微信。1==微信   3==qq
		$scope.go_share = function(index) {
			if($scope.openGuidShare()) {
				var param = new Object();
				param.title =  $scope.detail.company_name;//标题 
				param.desc = $scope.detail.company_profile;//简介
				param.thumb = $scope.detail.store_pic;//图片
				param.link = 'industryrankingsone/' + $scope.store_id;
				GoShare.do_share(param, index);
			} 
		}
		
		//分享（自定义每个页面的参数）
		$scope.go_share_wx = function() {
			//分享打开
			GoWapAuth.execisoff(false);
			//设置分享
			var param = new Object();
			param.title =  $scope.detail.company_name;//标题 
			param.desc = $scope.detail.company_profile;//简介
			param.thumb = $scope.detail.store_pic;//图片
			param.link = 'industryrankingsone/' + $scope.store_id;
			GoWapAuth.execshare(param);
		}
	}

	controller.$inject = ['$scope', 'Industryrankingsone', '$stateParams', 'GoPage','GoShare','GoDialog','GoWapAuth'];

	return app.registerController("industryrankingsonectrl",controller);
});